package com.bawei.module_home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_home.adapter.DeviceAdapter.DeviceViewHolder
import com.bawei.module_home.databinding.ItemDeviceBinding
import com.bawei.module_home.databinding.ItemSignBinding
import com.bawei.module_home.http.HomeServiceViewModel
import com.bawei.module_home.model.SignResult
import com.bawei.module_home.ui.sign.SignsActivity
/**
 *author：yjk
 *description:
 *date：2025/6/16
*/
class SignAdapter:RecyclerView.Adapter<SignAdapter.SignViewHolder>(){
    val list=mutableListOf<SignResult>()
    var onItemClick: ((SignResult, Int) -> Unit)? = null
    var onItemLongClick: ((SignResult, Int) -> Unit)? = null

    fun setData(data:List<SignResult>){
        list.clear()
        list.addAll(data)
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SignViewHolder {
        val binding= ItemSignBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return SignViewHolder(binding).apply {

            itemView.setOnClickListener {
                val index=bindingAdapterPosition
                onItemClick?.invoke(list[index], index)
            }
            itemView.setOnLongClickListener {
                val index=bindingAdapterPosition
                onItemLongClick?.invoke(list[index], index)
                true
            }
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: SignViewHolder, position: Int) {
        val binding= DataBindingUtil.getBinding<ItemSignBinding>(holder.itemView) ?:return
        binding.signItem=list[position]

    }
    class SignViewHolder(item: ItemSignBinding): RecyclerView.ViewHolder(item.root)
}